home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Semaphore / Source / CAppearanceApp.cp next >
Text File  |  2000-06-23  |  5KB  |  187 lines

  1. // ===========================================================================
  2. //    CAppearanceApp.cp         ©1994-1999 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //    This file contains the starter code for a basic PowerPlant project
  5.  
  6. #include "CAppearanceApp.h"
  7.  
  8. #include <LGrowZone.h>
  9. #include <PP_Messages.h>
  10. #include <PP_Resources.h>
  11. #include <UDrawingState.h>
  12. #include <UMemoryMgr.h>
  13. #include <URegistrar.h>
  14. #include <UEnvironment.h>
  15.  
  16. #include <UControlRegistry.h>
  17.  
  18. #include <LWindow.h>
  19.  
  20. #include <Appearance.h>
  21. #include "CSemaphorePicture.h"
  22.  
  23.  
  24.     // Constant declarations
  25. const ResIDT    PPob_MainWindow            = 128;
  26. const PaneIDT    Pane_Picture                    = 1;
  27.  
  28. // ===========================================================================
  29. //    • main
  30. // ===========================================================================
  31.  
  32. int main()
  33. {                            
  34.         // Set Debugging options
  35.     SetDebugThrow_(debugAction_Alert);
  36.     SetDebugSignal_(debugAction_Alert);
  37.  
  38.         // Initialize Memory Manager. Parameter is the number of
  39.         // master pointer blocks to allocate
  40.     InitializeHeap(3);
  41.     
  42.         // Initialize standard Toolbox managers
  43.     UQDGlobals::InitializeToolbox(&qd);
  44.     
  45.         // Install a GrowZone to catch low-memory situations    
  46.     new LGrowZone(20000);
  47.  
  48.         // Create the application object and run
  49.     CAppearanceApp    theApp;
  50.     theApp.Run();
  51.     
  52.     return 0;
  53. }
  54.  
  55.  
  56. // ---------------------------------------------------------------------------
  57. //    • CAppearanceApp                                [public]
  58. // ---------------------------------------------------------------------------
  59. //    Application object constructor
  60.  
  61. CAppearanceApp::CAppearanceApp()
  62. {
  63.         // Register ourselves with the Appearance Manager
  64.     if (UEnvironment::HasFeature(env_HasAppearance)) {
  65.         ::RegisterAppearanceClient();
  66.     }
  67.  
  68.     RegisterClasses();
  69. }
  70.  
  71.  
  72. // ---------------------------------------------------------------------------
  73. //    • ~CAppearanceApp                                [public, virtual]
  74. // ---------------------------------------------------------------------------
  75. //    Application object destructor
  76.  
  77. CAppearanceApp::~CAppearanceApp()
  78. {
  79.     // Nothing
  80. }
  81.  
  82.  
  83. // ---------------------------------------------------------------------------
  84. //    • StartUp                                        [protected, virtual]
  85. // ---------------------------------------------------------------------------
  86. //    Perform an action in response to the Open Application AppleEvent.
  87. //    Here, issue the New command to open a window.
  88.  
  89. void
  90. CAppearanceApp::StartUp()
  91. {
  92.     ObeyCommand(cmd_New, nil);
  93. }
  94.  
  95.  
  96. // ---------------------------------------------------------------------------
  97. //    • ObeyCommand                                    [public, virtual]
  98. // ---------------------------------------------------------------------------
  99. //    Respond to Commands. Returns true if the Command was handled, false if not.
  100.  
  101. Boolean
  102. CAppearanceApp::ObeyCommand(
  103.     CommandT    inCommand,
  104.     void*        ioParam)
  105. {
  106.     Boolean        cmdHandled = true;    // Assume we'll handle the command
  107.  
  108.     switch (inCommand) {
  109.  
  110.         case cmd_New: {
  111.             LWindow* theWindow = LWindow::CreateWindow(PPob_MainWindow, this);
  112.             ThrowIfNil_(theWindow);
  113.             
  114.             // attach app as listener
  115.             CSemaphorePicture* picture = dynamic_cast<CSemaphorePicture*> (theWindow->FindPaneByID(Pane_Picture));
  116.             ThrowIfNil_(picture);
  117.             theWindow->SetLatentSub(picture);
  118.  
  119.             theWindow->Show();
  120.             break;
  121.         }
  122.  
  123.         default: {
  124.             cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  125.             break;
  126.         }
  127.     }
  128.     
  129.     return cmdHandled;
  130. }
  131.  
  132.  
  133. // ---------------------------------------------------------------------------
  134. //    • FindCommandStatus                                [public, virtual]
  135. // ---------------------------------------------------------------------------
  136. //    Determine the status of a Command for the purposes of menu updating.
  137.  
  138. void
  139. CAppearanceApp::FindCommandStatus(
  140.     CommandT    inCommand,
  141.     Boolean&    outEnabled,
  142.     Boolean&    outUsesMark,
  143.     UInt16&        outMark,
  144.     Str255        outName)
  145. {
  146.     switch (inCommand) {
  147.  
  148.         case cmd_New: {
  149.             outEnabled = true;
  150.             break;
  151.         }
  152.  
  153.         default: {
  154.             LApplication::FindCommandStatus(inCommand, outEnabled,
  155.                                             outUsesMark, outMark, outName);
  156.             break;
  157.         }
  158.     }
  159. }
  160.  
  161.  
  162. // ---------------------------------------------------------------------------
  163. //    • RegisterClasses                                [protected]
  164. // ---------------------------------------------------------------------------
  165. //    To reduce clutter within the Application object's constructor, class
  166. //    registrations appear here in this seperate function for ease of use.
  167.  
  168. void
  169. CAppearanceApp::RegisterClasses()
  170. {
  171.         // Register core PowerPlant classes.
  172.     RegisterClass_(LWindow);
  173.  
  174.         // Register the Appearance Manager/GA classes. You may want
  175.         // to remove this use of UControlRegistry and instead perform
  176.         // a "manual" registration of the classes. This cuts down on
  177.         // extra code being linked in and streamlines your app and
  178.         // project. However, use UControlRegistry as a reference/index
  179.         // for your work, and ensure to check UControlRegistry against
  180.         // your registrations each PowerPlant release in case
  181.         // any mappings might have changed.
  182.         
  183.     UControlRegistry::RegisterClasses();
  184.     
  185.     // Register my class
  186.     RegisterClass_(CSemaphorePicture);
  187. }